package com.bkgy.jobs;

import com.bkgy.controller.tPdiDataL3Tcm2280.service.IRepTcmOutputHourService;
import com.bkgy.controller.tpdol3data.service.ITPdoL3Tcm2280Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;

/**
 * 1.构建小时段酸轧产量计划 REP_TCM_OUTPUT_HOUR
 * 2.构建当日产量预计
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class OutputTaskJob {
    private final ITPdoL3Tcm2280Service tcm2280Service;
    private final IRepTcmOutputHourService tcmOutputHourService;

    private int hour = -1;

    public void exec() {
        //任务1：酸轧产量小时段报表基础数据
        try {
            //更新前2小时段数据，
            tcmOutputHourService.buildOutput2HourJob();
            //当下数据
            tcmOutputHourService.currentHourOutput();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }

        //任务2：日计划，每小时更新一次
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        int h = cal.get(Calendar.HOUR_OF_DAY);
        try {
            if (hour != h) {
                tcmOutputHourService.buildOutput2280Day();
                hour = h;
            }
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}
